<%-- 
    Document   : CCAction
    Created on : 03 15, 12, 3:12:12 PM
    Author     : RES
--%>

<%@page import="UserPackage.Hasher"%>
<%@page import="UserPackage.cardManager"%>
<%@page import="UserPackage.card"%>
<%@page import="UserPackage.inputChecker"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        
    </head>
    <body>
        <%
            boolean result=false;
            
            String cardName = request.getParameter("CCName");
            String cardNum = request.getParameter("CCNum");
            String cardType = request.getParameter("CCType");
            String expMon = request.getParameter("CCExpMon");
            String expDay = request.getParameter("CCExpDay");
            String expYr = request.getParameter("CCExpYr");
            String username = (String)session.getAttribute("username");
           
      
            inputChecker check = new inputChecker();
            if(check.stringCompare(cardName) && check.stringCompare(cardNum))
            {
              card newCard = new card();
              
              newCard.setCardName(cardName);
              newCard.setCardNum(cardNum);
              newCard.setCardType(cardType);
              newCard.setCardExpMon(expMon);
              newCard.setCardExpDay(expDay);
              newCard.setCardExpYr(expYr);
              newCard.setUsername(username);
              String hash = new Hasher().passHasher(cardNum);
              newCard.setCardHash(hash);
              
              result = new cardManager().addCC(newCard);
              
              if(result == true)
                  response.sendRedirect("userHomePage.jsp");
              
              else
                  response.sendRedirect("creditCard.jsp");
                                
            
            }
                       else
                           response.sendRedirect("creditCard.jsp");
            
        %>
    </body>
</html>
